﻿using System;
using System.Configuration;

namespace PlugIn.Configuration
{
    /// <summary>
    /// 组件配置节点类
    /// 作者：Zuowenjun
    /// 2016-3-30
    /// </summary>
    public class CompoentConfigurationSection : ConfigurationSection
    {
        private static readonly ConfigurationProperty s_property = new ConfigurationProperty(
        string.Empty, typeof(ComponentCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

        [ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
        public ComponentCollection Components
        {
            get
            {
                return (ComponentCollection)base[s_property];
            }
        }


        [ConfigurationProperty("basePath", IsRequired = false)]
        public string BasePath
        {
            get
            {
                return ReMapBasePath(this["basePath"].ToString());
            }
            set
            {
                this["basePath"] = ReMapBasePath(value);
            }
        }

        private string ReMapBasePath(string basePath)
        {
            if (basePath.Trim().StartsWith("~\\"))
            {
                basePath = basePath.Replace("~\\", AppDomain.CurrentDomain.BaseDirectory + "\\");
            }
            return basePath;
        }
    }
}
